package com.sky.sd.common.web.response;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * <br/>功能: 统一响应
 * <br/>版本: 1.0
 * <br/>开发人员: 弓振
 * <br/>创建日期: 2020/6/17 11:39
 * <br/>修改日期: 2020/6/17 11:39
 * <br/>修改列表:
 */
@Data
@ToString
public class Result<T> implements Serializable {

    private int code;

    private String msg;

    private T bean;

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T bean) {
        Result<T> result = new Result<>();
        result.code = ResultType.SUCCESS.getCode();
        result.msg = ResultType.SUCCESS.getMsg();
        result.bean = bean;
        return result;
    }

    public static <T> Result<T> fail(String msg) {
        return fail(ResultType.FAIL.getCode(), msg);
    }

    public static <T> Result<T> fail(String msg, T bean) {
        return fail(ResultType.FAIL.getCode(), msg, bean);
    }

    public static <T> Result<T> fail(ResultType resultCode) {
        return fail(resultCode.getCode(),resultCode.getMsg());
    }

    public static <T> Result<T> fail(ResultType resultCode, T bean) {
        return fail(resultCode.getCode(), resultCode.getMsg(), bean);
    }

    public static <T> Result<T> fail(int code, String msg) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> fail(int code, String msg, T bean) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        result.bean = bean;
        return result;
    }
}
